<?php
class ShareModel extends Model
{
	function getShareList($map,$pageRow=40,$field='',$order=''){
		if(empty($field)) $field = '*';
		if(empty($order)) $order = 'id desc';
		
		if($pageRow){
			$result = $this->where($map)->field($field)->order($order)->findPage($pageRow);
			foreach ($result['data'] as &$v){
				$v['data'] = unserialize($v['data']);
				$v['url']  = $this->_getTitleURL($v);
			}
			return $result;	
		}
		
		$result = $this->where($map)->field($field)->order($order)->findAll();
		foreach ($result as &$v){
			$v['data'] = unserialize($v['data']);
			$v['url']  = $this->_getTitleURL($v);
		}
		return $result;		
	}
	
	function _getTitleURL($vo){
		switch ($vo['temp']){//app=wiki&mod=Index&act=detail&id=84#
			case 'share_ask': $url = U('ask/index/detail','id='.$vo['aimId']); break;
			case 'share_blog': $url = U('blog/index/detail',array('id'=>$vo['aimId'],'uid'=>$vo['fromUid'])); break;
			case 'group_share_blog': $url = U('group/blog/detail',array('id'=>$vo['aimId'],'gid'=>$vo['data']['gid'])); break;
			case 'share_wiki': $url = U('wiki/Index/detail','id='.$vo['aimId']); break;
			case 'group_share_wiki': $url = U('group/Wiki/detail',array('id'=>$vo['aimId'],'gid'=>$vo['data']['gid'])); break;
			case 'share_topic': $url = U('bbs/Index/detail',array('id'=>$vo['aimId'])); break;
			case 'group_share_file': $url = U('group/File/detail',array('fid'=>$vo['aimId'],'gid'=>$vo['data']['gid'])); break;
			case 'group_share_topic': $url = U('group/Forum/detail',array('tid'=>$vo['aimId'],'gid'=>$vo['data']['gid'])); break;
		}

		return $url;
	}	

}
?>